'''
Created on Dec 1, 2012

@author: quirino
'''
from unittest.case import TestCase
from cupy.utils import merge, intersect, to_list

class UtilsTestCase(TestCase):


    def test_merge_dict(self):
        d1 = {'a':6, 'b': 3}
        d2 = {'b': 5, 'c': 7}
        exp = {'a':6, 'b': 5, 'c': 7}
        res = merge(d1, d2)
        self.assertEquals(exp, res)
        
    def test_intersect(self):
        d1 = {'a':6, 'b': 3}
        d2 = {'b': 3, 'c': 7}
        exp = set([('b', 3)])
        res = intersect(d1.viewitems(), d2.viewitems())
        self.assertEquals(exp, res)
    
    def test_to_list_dict(self):
        d1 = {'a':6, 'b': 3}
        res = to_list(d1)
        exp = [('a', 6), ('b',3)]
        self.assertEquals(exp, res)
    
    def test_to_list_tuple(self):
        t1 = (('a',6), ('b', 5))
        res = to_list(t1)
        exp = [('a', 6), ('b', 5)]
        self.assertEquals(exp, res)

    def test_to_list_tuple_single_value(self):
        t1 = ('a',6)
        res = to_list(t1)
        exp = ['a', 6]
        self.assertEquals(exp, res)
    
    def test_to_list_list(self):
        l1 = ['a',6]
        res = to_list(l1)
        exp = ['a', 6]
        self.assertEquals(exp, res)
    